home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!news1!ind-003-236-135
- From: dlmiller@iquest.net (Doug Miller)
- Subject: Re: while loop problem
- X-Nntp-Posting-Host: ind-003-236-135.iquest.net
- Message-ID: <DoBAC8.K3o@iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Network Services
- X-Newsreader: News Xpress Version 1.0 Beta #2.1
- References: <Pine.OSF.3.91.960312133449.7844B-100000@io.UWinnipeg.ca> <Do6DB0.EtE@microunity.com> <Pine.A32.3.91.960312171258.149477C-100000@black.weeg.uiowa.edu>
- Date: Fri, 15 Mar 1996 13:50:21 GMT
-
- The Amorphous Mass <robinson@blue.weeg.uiowa.edu> wrote:
-
- +On Tue, 12 Mar 1996, Tom Sanders wrote:
- +
- +> Bill Simpson <wsimpson@uwinnipeg.ca> writes:
- +> |> Consider the following code fragment:
- +> |>
- +> |> y=2000; z=1000;
- +> |> x=0;
- +> |> while(x<=XMAX)
- +> |> {
- +> |> x+=(int) erand(mean);
- +> |> setdot(x,y,z);
- +> |> }
- +> |>
- +> |> The above code will also attempt to plot one point at an x value >XMAX
- +> |> before it terminates.
- +> |>
- +> |> Is there a nice way to write the code so it works properly?
- +>
- +> y=2000; z=1000;
- +> x=0;
- +> do {
- +> x+=(int) erand(mean);
- +> setdot(x,y,z);
- +> } while(x<=XMAX)
- +
- + This has exactly the same problem as the original loop, because it adds
- +erand() to x and calls setdot() _before_ checking x's value against XMAX.
- +Also, you left off the semicolon after the while ().
- +
- +/**James Robinson***********************
-
- Well, let's give him a correct answer.
-
- In the *original* loop, just change the test (x <= XMAX) to (x < XMAX).
- There. That wasn't so hard, was it?
-
- -- Doug.
-